Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix yaml duplicate reaction check #866

Merged
merged 6 commits into from
Jun 30, 2020

Conversation

speth
Copy link
Member

@speth speth commented Jun 18, 2020

Changes proposed in this pull request

***********************************************************************
InputFileError thrown by Kinetics::checkDuplicates:
Error on lines 1531 and 1816 of ./dup.yaml:
Undeclared duplicate reactions detected:
Reaction 325: NNH + O2 <=> HO2 + N2
Reaction 206: NNH + O2 <=> HO2 + N2

|  Line |
|  1526 | - equation: NNH + M <=> N2 + H + M  # Reaction 205
|  1527 |   type: three-body
|  1528 |   rate-constant: {A: 1.3e+14, b: -0.11, Ea: 4980.0}
|  1529 |   efficiencies: {H2: 2.0, H2O: 6.0, CH4: 2.0, CO: 1.5, CO2: 2.0, C2H6: 3.0,
|  1530 |     AR: 0.7}
>  1531 > - equation: NNH + O2 <=> HO2 + N2  # Reaction 206
            ^
|  1532 |   rate-constant: {A: 5.0e+12, b: 0.0, Ea: 0.0}
|  1533 | - equation: NNH + O <=> OH + N2  # Reaction 207
|  1534 |   rate-constant: {A: 2.5e+13, b: 0.0, Ea: 0.0}
...
|  1811 |   rate-constant: {A: 2.41e+13, b: 0.0, Ea: 0.0}
|  1812 | - equation: HO2 + C3H7 <=> O2 + C3H8  # Reaction 323
|  1813 |   rate-constant: {A: 2.55e+10, b: 0.255, Ea: -943.0}
|  1814 | - equation: HO2 + C3H7 => OH + C2H5 + CH2O  # Reaction 324
|  1815 |   rate-constant: {A: 2.41e+13, b: 0.0, Ea: 0.0}
>  1816 > - equation: NNH + O2 <=> HO2 + N2  # Reaction 206 (again)
            ^
|  1817 |   rate-constant: {A: 5.0e+12, b: 0.0, Ea: 0.0}
|  1818 | - equation: CH3 + C3H7 <=> 2 C2H5  # Reaction 325
|  1819 |   rate-constant: {A: 1.927e+13, b: -0.32, Ea: 0.0}
***********************************************************************
  • Replace the incomplete duplicate reaction check in ck2yaml.py with the full one done in the C++ Kinetics class, and parse the output of that error to provide line numbers of the duplicate reactions in the original input file, e.g.:
Wrote YAML mechanism file to './duplicate-reactions.yaml'.
Mechanism contains 4 species and 7 reactions.
Validating mechanism...FAILED.
Undeclared duplicate reaction C2 + H2 <=> C2H + H
found on lines 30 and 31 of  the kinetics input file.
  • A little bit of refactoring of AnyValue and AnyMap to make this a bit easier.

Checklist

  • There is a clear use-case for this code change
  • The commit message has a short title & references relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • The pull request is ready for review

@codecov
Copy link

codecov bot commented Jun 18, 2020

Codecov Report

Merging #866 into master will decrease coverage by 0.00%.
The diff coverage is 84.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #866      +/-   ##
==========================================
- Coverage   70.49%   70.49%   -0.01%     
==========================================
  Files         375      375              
  Lines       45649    45671      +22     
==========================================
+ Hits        32182    32197      +15     
- Misses      13467    13474       +7     
Impacted Files Coverage Δ
src/thermo/ThermoFactory.cpp 83.81% <ø> (ø)
src/base/AnyMap.cpp 83.83% <80.39%> (-0.01%) ⬇️
src/kinetics/Kinetics.cpp 83.85% <88.88%> (-0.36%) ⬇️
include/cantera/base/AnyMap.h 100.00% <100.00%> (ø)
src/kinetics/KineticsFactory.cpp 96.38% <100.00%> (-1.12%) ⬇️
src/kinetics/Reaction.cpp 87.12% <0.00%> (-0.38%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df37795...1e1340b. Read the comment docs.

@speth speth force-pushed the fix-yaml-duplicate-reaction-check branch from 22f7f69 to 83f2c45 Compare June 18, 2020 18:13
Copy link
Member

@bryanwweber bryanwweber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this @speth! Just a few small things I noticed.

interfaces/cython/cantera/ck2yaml.py Outdated Show resolved Hide resolved
interfaces/cython/cantera/ck2yaml.py Outdated Show resolved Hide resolved
interfaces/cython/cantera/ck2yaml.py Outdated Show resolved Hide resolved
interfaces/cython/cantera/ck2yaml.py Outdated Show resolved Hide resolved
@speth speth force-pushed the fix-yaml-duplicate-reaction-check branch from 83f2c45 to 93a6e84 Compare June 30, 2020 00:00
@speth speth requested a review from bryanwweber June 30, 2020 00:16
Copy link
Member

@bryanwweber bryanwweber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good now! I have a question below which is partly for my understanding, but may be worth adding a comment in the code for future us as well, depending on the answer.

if match:
reactions.append(int(match.group(1))-1)

if len(reactions) != 2:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this check necessary? From my quick test, adding a third duplicate reaction still only shows two of them. Are there other error conditions that can reach this function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the error from Kinetics::checkDuplicates should only ever indicate two reactions. What I'm trying to hedge against is (a) the possibility there's some case where that error message doesn't have the expected format, or (b) some future change breaks this attempt at parsing the error message. If either of those happens, I'd rather output the original message from Kinetics::checkDuplicates than some error message generated caused by reactions not having the the expected number of entries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments to show_duplicate_reactions which will hopefully make some of this clear to our future selves. 😂

Use the more comprehensive duplicate reaction check in
Kinetics::checkDuplicates when validating the mechanism.

Parse the error message generated by Kinetics::checkDuplicates to determine
the line number in the original input file, which is more useful to users
than the line number in the newly-generated YAML file.
@speth speth force-pushed the fix-yaml-duplicate-reaction-check branch from 93a6e84 to 1e1340b Compare June 30, 2020 01:48
@speth speth merged commit 79a4163 into Cantera:master Jun 30, 2020
@speth speth deleted the fix-yaml-duplicate-reaction-check branch July 23, 2024 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate reactions not being caught in ck2yaml
2 participants